package avicit.im.lantop.basic.fieldmapset.action;

import avicit.cbb.appreg.service.CommSysInfoIntfsService;
import avicit.cbb.fondsmanage.service.CbbFondsDbIntfsService;
import avicit.cbb.searcheng.service.CbbSearchengIntfsService;
import avicit.cbb.tabledefine.service.CommTableManagerIntfsService;
import avicit.im.lantop.archiveclassmanager.service.ArchiveClassManagerIntfsService;
import avicit.im.lantop.archiveclassmanager.service.api.ArchiveClassManagerIntfsServiceApi;
import avicit.im.lantop.basic.fieldmapset.dao.LantopFieldMapSetManagerDao;
import avicit.im.lantop.basic.fieldmapset.dao.api.LantopFieldMapSetManagerDaoApi;
import avicit.im.lantop.basic.fieldmapset.domain.LantopConditionSet;
import avicit.im.lantop.basic.fieldmapset.domain.LantopFieldRelateSet;
import avicit.im.lantop.basic.fieldmapset.service.LantopFieldMapSetService;
import avicit.im.lantop.basic.fieldmapset.service.api.LantopFieldMapSetServiceApi;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.api.syslookup.SysLookupAPI;
import avicit.platform6.api.syslookup.dto.SysLookupSimpleVo;
import avicit.platform6.api.syslookup.impl.SysLookupAPImpl;
import avicit.platform6.api.sysuser.SysOrgAPI;
import avicit.platform6.api.sysuser.dto.SysOrg;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.spring.SpringFactory;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import org.apache.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：钟一华</p>
 * <p>邮箱：zhongyih@avicit.com</p>
 * <p>创建时间： 2015-11-3 下午2:18:13 </p>
 * <p>类说明：字段对应设置controller</p>
 * <p>修改记录： </p>
 */
@Controller
@SuppressWarnings("deprecation")
@RequestMapping("/LantopFieldMapSetController")
public class LantopFieldMapSetController {

	private Logger logger = Logger.getLogger(this.getClass());
	@Resource
	LantopFieldMapSetServiceApi lantopFieldMapSetService;
	@Resource
	CommSysInfoIntfsService commSysInfoIntfsService;
	@Resource
	CommTableManagerIntfsService commTableManagerIntfsService;
	@Resource
	ArchiveClassManagerIntfsServiceApi archiveClassManagerIntfsService;
	@Resource
	CbbSearchengIntfsService cbbSearchengIntfsService;
	@Autowired(required = true)
	LantopFieldMapSetManagerDaoApi lantopFieldMapSetManagerDao;
	// 获取通用代码
	SysLookupAPI upLoader = SpringFactory.getBean(SysLookupAPImpl.class);
	@Autowired
	CbbFondsDbIntfsService cbbFondsDbIntfsService;
	
	@Autowired
	SysOrgAPI sysOrgAPI;

	 // 运算符选择
	 Collection<SysLookupSimpleVo> lanTopOperCharacter = upLoader.getLookUpListByType("CBB_OPER_CHARACTER");
	 // 或者/并且选择
	 Collection<SysLookupSimpleVo> lanTopLogicOper = upLoader.getLookUpListByType("CBB_LOGIC_OPER");

	/**
	 * 前台展开时异步加载树
	 * 
	 * @author 朱锋
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */

	@RequestMapping("/findChildsByNodeId")
	@ResponseBody
	public Map<String,Object> findChildsByNodeId(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		nodes = this.archiveClassManagerIntfsService.getArchiveClassTreeNodeToTableInfoByIntfs(ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId());
		List<Map<String, Object>> publicFieldList =  this.lantopFieldMapSetService.getPublicFieldInfo();
		Map<String, Object> modelMap = new HashMap<String, Object>();
		Map<String, Object> FolderMap = new HashMap<String, Object>();
		for (int i = 0; i < publicFieldList.size(); i++) {
			Map<String, Object> map = publicFieldList.get(i);
			String archiveType = (String) map.get("ARCHIVE_TYPE");
			if ("-1".equals(archiveType)) {
				modelMap = map;
			} else {
				FolderMap = map;
			}
		}

		if (ThreadContextHelper.getOrgId()!="ORG_ROOT"||!ThreadContextHelper.getOrgId().equals("ORG_ROOT")){
			int index = 0;
			List<TreeNode> treeNodeList = nodes.get(0).getChildren();
			List<TreeNode> childrenDataList = new ArrayList<>();
			boolean deleteFlag = false;
			for (TreeNode childNode : treeNodeList){
				String text = childNode.getText();
				if (text.equals("外部业务系统归档接收管理")){
					deleteFlag = true;
					break;
				}
				index++;
			}
			if (deleteFlag){
				nodes.get(0).getChildren().remove(index);// 移除
			}
			treeNodeList = new ArrayList<>();
			treeNodeList = this.archiveClassManagerIntfsService.getArchiveClassTreeNodeToTableInfoByIntfs("ORG_ROOT","");
			childrenDataList = treeNodeList.get(0).getChildren();
			for (TreeNode childNode : childrenDataList){
				String text = childNode.getText();
				if (text.equals("外部业务系统归档接收管理")){
					nodes.get(0).getChildren().add(childNode); // 补充
				}
			}
		}
		TreeNode model = new TreeNode();
		String ridModel = (String) modelMap.get("ID");
		String rnameModel = (String) modelMap.get("ARCHIVE_CLASS_NODE_NAME");
		String parentIdModel = (String) modelMap.get("PARENT_ID");
		model.setId(ridModel);
		model.setText(rnameModel);
		model.setAttributes(modelMap);
		model.set_parentId(parentIdModel);
		model.setIconCls("icon-im-newntable");
		TreeNode folder = new TreeNode();
		String rid = (String) FolderMap.get("ID");
		String rname = (String) FolderMap.get("ARCHIVE_CLASS_NODE_NAME");
		String parentId = (String) FolderMap.get("PARENT_ID");
		folder.setId(rid);
		folder.setText(rname);
		folder.setAttributes(FolderMap);
		folder.set_parentId(parentId);
		folder.setState("open");
		folder.setIconCls("icon-im-newnmodulelib");
		folder.getChildren().add(model);
		nodes.get(0).getChildren().add(folder);
		maps.put("data", nodes);
		return maps;
	}

	/**
	 * 前台展开时异步加载树(条件设置添加页面)
	 * 
	 * @author 朱锋
	 * @param
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */

	@RequestMapping("/findChildsByNodeIdByCondition")
	public ModelAndView findChildsByNodeIdByCondition(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView();
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		nodes = this.lantopFieldMapSetService.getArchiveClassTreeNodeToTableInfoByCondition(SessionHelper.getCurrentOrgId(request), SessionHelper.getCurrentDeptId(request));
		mv.addObject("data", nodes);
		return mv;
	}

	/**
	 * 获取字段对应设置列表
	 * 
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getLantopFieldRelateData")
	@ResponseBody
	public Map<String,Object> getLantopFieldMapSetData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String orgId = ThreadContextHelper.getOrgId();
		String sourceTableId = request.getParameter("sourceTableId");
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("sourceTableId", sourceTableId);
		parameter.put("orgId", orgId);
		Paging<LantopFieldRelateSet> page = new Paging<LantopFieldRelateSet>();
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = this.lantopFieldMapSetService.getPageRelateSetList(page, parameter);
		map.put("total", result.getEntityCount()); // total键
		map.put("rows", result.getEntities()); // rows键 存放每页记录 list
		return map;
	}

	/**
	 * 条件设置列表
	 * 
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getLantopConditionSetData")
	public ModelAndView getLantopConditionSetData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView("");
		Map<String, Object> parameter = new HashMap<String, Object>();
		Paging<LantopConditionSet> page = new Paging<LantopConditionSet>();
		String pageNo = request.getParameter("page");// 取得当前页码
		String pageSize = request.getParameter("rows");// 取得一页显示的数量
		page.setPageSize(ComUtil.getPageSize(pageSize));
		page.setPageNo(ComUtil.getPageNo(pageNo));
		Page<Map<String, Object>> result = this.lantopFieldMapSetService.getPageRConditionSetList(page, parameter);
		mav.addObject("total", result.getEntityCount()); // total键
		mav.addObject("rows", result.getEntities()); // rows键 存放每页记录 list
		return mav;
	}

	/**
	 * 获取源库表列信息
	 * 
	 * @author 朱锋
	 * @param response
	 * @param request
	 * @return ModelAndView
	 * @throws Exception
	 *             ModelAndView
	 */
	@RequestMapping(value = "/getSetData")
	public ModelAndView getSetData(HttpServletResponse response, HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView("");
		String myTableId = request.getParameter("myTableId");// 自己表ID
		String elseTableId = request.getParameter("elseTableId");// 对方表ID
		String tgtNodeId = request.getParameter("tgtNodeId");// 目标节点ID
		String tgtOrsource = request.getParameter("tgtOrsource");// 刷新标识("source"源表
																	// "tgt"目标表)
		String sysId = request.getParameter("sysId");// 系统标识
		String orgId = SessionHelper.getCurrentOrgId(request);
		String deptId = SessionHelper.getCurrentDeptId(request);
		// 根据表ID获取表信息
		List<Map<String, Object>> list = this.commTableManagerIntfsService.getCbbTabColumnsByIsAllByIntfs(orgId, deptId, sysId, myTableId, "N");
		// 给表格数据添加对应颜色
		if (!"".equals(elseTableId)) { // 如果对方表ID不为空
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = list.get(i);
				String relateSetId = this.lantopFieldMapSetService.getRelateSetIdByIds(myTableId, elseTableId, tgtNodeId, sysId, tgtOrsource);// 对应设置主表ID
				if (!"".equals(relateSetId)) {
					String tnameEn = String.valueOf(map.get("COL_NAME"));// 目标表列英文名
					List<Object[]> sourceList = lantopFieldMapSetService.getSourceColByRidAndTcn(relateSetId, tnameEn);
					if (sourceList.size() > 0) {
						String cname = String.valueOf(sourceList.get(0)[1]);
						String ename = String.valueOf(sourceList.get(0)[0]);
						if (!"".equals(cname) && null != cname) {
							// 如果存在
							map.put("SOURCE_COL_LABEL", "<font color='green'>" + cname + "</font>");
							List<Map<String, Object>> colnumlist = this.commTableManagerIntfsService.getCbbColumnsByTableIdAndColNameByIntfs(elseTableId, ename);
							if (colnumlist.size() > 0) {
								map.put("ATTRIBUTE_03", String.valueOf(colnumlist.get(0).get("ID")));
							}
						} else {
							map.put("SOURCE_COL_LABEL", "");
							map.put("ATTRIBUTE_03", "");
						}
					}
				}
			}
		}
		mav.addObject("rows", list); // rows键 存放每页记录 list
		return mav;
	}


	/**
	 * 设置对应跳转
	 *
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toMapSetPages")
	public ModelAndView toMapSetPages(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String flag = request.getParameter("flag");// 添加，编辑标识（添加'add' 编辑'edit'）
		String type = request.getParameter("type");// 节点属性标识（Y 真实表 N 虚拟表 ）
		String sourceTableId = request.getParameter("sourceTableId");// 源表ID
		String sourceTableLable = request.getParameter("sourceTableLable");// 源表名称
		String tgtTableId = request.getParameter("tgtTableId");// 编辑或公共字段时，目标表ID
		String tgtTableLable = request.getParameter("tgtTableLable");// 编辑或公共字段时，目标表名称
		String tgtClassNodeId = request.getParameter("tgtClassNodeId");// 编辑时，目标节点ID
		String sourceTableName = request.getParameter("sourceTableName");// 源库表名
		String orgId = request.getParameter("orgId");// 目标表全宗
		String orgType = request.getParameter("orgType");//目标表标识
		String nodeId=request.getParameter("nodeId"); //节点id
		// sysId
		String sysCode = request.getParameter("sysId");// 系统标识
		String sysId = "LANTOP";
		try {
			sourceTableLable = URLDecoder.decode(sourceTableLable, "utf-8");
			sourceTableLable = URLDecoder.decode(sourceTableLable, "utf-8");
			tgtTableLable = URLDecoder.decode(tgtTableLable, "utf-8");
			tgtTableLable = URLDecoder.decode(tgtTableLable, "utf-8");
			sourceTableName = URLDecoder.decode(sourceTableName, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		// 判断是否为虚拟表，如果是，那么交换源表 和 目标表位置
		if ("N".equals(type) && "add".equals(flag)) {
			String value = "";// 中间变量
			value = sourceTableId;
			sourceTableId = tgtTableId;
			tgtTableId = value;

			value = sourceTableLable;
			sourceTableLable = tgtTableLable;
			tgtTableLable = value;
		}
		if(orgId!=""){
			mav.addObject("orgId", orgId);
			mav.addObject("orgType", orgType);
			mav.addObject("nodeId",nodeId);
		}
		mav.addObject("sourceTableName", sourceTableName);
		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("flag", flag);
		mav.addObject("type", type);
		mav.addObject("sourceTableId", sourceTableId);
		mav.addObject("sourceTableLable", sourceTableLable);
		mav.addObject("tgtTableId", tgtTableId);
		mav.addObject("tgtTableLable", tgtTableLable);
		mav.addObject("tgtClassNodeId", tgtClassNodeId.equals("null") ? "" : tgtClassNodeId);
		if(orgType.equals("1")){
			mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopFieldMapSetItems");
		}else{
			mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopFieldMapSetItem");
		}
		return mav;
	}


	/**
	 * 设置对应跳转
	 * 
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toMapSetPage")
	public ModelAndView toMapSetPage(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String flag = request.getParameter("flag");// 添加，编辑标识（添加'add' 编辑'edit'）
		String type = request.getParameter("type");// 节点属性标识（Y 真实表 N 虚拟表 ）
		String sourceTableId = request.getParameter("sourceTableId");// 源表ID
		String sourceTableLable = request.getParameter("sourceTableLable");// 源表名称
		String tgtTableId = request.getParameter("tgtTableId");// 编辑或公共字段时，目标表ID
		String tgtTableLable = request.getParameter("tgtTableLable");// 编辑或公共字段时，目标表名称
		String tgtClassNodeId = request.getParameter("tgtClassNodeId");// 编辑时，目标节点ID
		String sourceTableName = request.getParameter("sourceTableName");// 源库表名
		String orgId = request.getParameter("orgId");// 源库表名
		// sysId
		String sysCode = request.getParameter("sysId");// 系统标识
		String sysId = "LANTOP";
		try {
			sourceTableLable = URLDecoder.decode(sourceTableLable, "utf-8");
			sourceTableLable = URLDecoder.decode(sourceTableLable, "utf-8");
			tgtTableLable = URLDecoder.decode(tgtTableLable, "utf-8");
			tgtTableLable = URLDecoder.decode(tgtTableLable, "utf-8");
			sourceTableName = URLDecoder.decode(sourceTableName, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		// 判断是否为虚拟表，如果是，那么交换源表 和 目标表位置
		if ("N".equals(type) && "add".equals(flag)) {
			String value = "";// 中间变量
			value = sourceTableId;
			sourceTableId = tgtTableId;
			tgtTableId = value;

			value = sourceTableLable;
			sourceTableLable = tgtTableLable;
			tgtTableLable = value;
		}
		if(orgId!=""){
			mav.addObject("orgId", orgId);
		}
		mav.addObject("sourceTableName", sourceTableName);
		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("flag", flag);
		mav.addObject("type", type);
		mav.addObject("sourceTableId", sourceTableId);
		mav.addObject("sourceTableLable", sourceTableLable);
		mav.addObject("tgtTableId", tgtTableId);
		mav.addObject("tgtTableLable", tgtTableLable);
		mav.addObject("tgtClassNodeId", tgtClassNodeId.equals("null") ? "" : tgtClassNodeId);
		mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopFieldMapSetItem");
		return mav;
	}

	/**
	 * 条件设置跳转
	 * 
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toConditionSetPage")
	public ModelAndView toConditionSetPage(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String nodeId = request.getParameter("nodeId");
		String nodeName = request.getParameter("nodeName");
		String sysCode = request.getParameter("sysId");
		String nodeCode = request.getParameter("nodeCode");
		// sysId
		String sysId = "LANTOP";
		try {
			nodeName = URLDecoder.decode(nodeName, "utf-8");
			nodeName = URLDecoder.decode(nodeName, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		mav.addObject("dialogId", dialogId);
		mav.addObject("nodeId", nodeId);
		mav.addObject("nodeName", nodeName);
		mav.addObject("sysId", sysId);
		mav.addObject("nodeCode", nodeCode);
		mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopConditionSetItem");
		return mav;
	}

	/**
	 * 条件设置添加页面跳转
	 * 
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toConditionSetAddPage")
	public ModelAndView toConditionSetAddPage(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String sysCode = request.getParameter("sysId");
		String nodeCode = request.getParameter("nodeCode");
		// sysId
		String sysId = "LANTOP";
		mav.addObject("dialogId", dialogId);
		mav.addObject("sysId", sysId);
		mav.addObject("nodeCode", nodeCode);
		mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopConditionSetAddItem");
		return mav;
	}

	/**
	 * 条件设置编辑页面跳转
	 * 
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toConditionSetEditPage")
	public ModelAndView toConditionSetEditPage(HttpServletRequest request) throws Exception {
		Collection<SysLookupSimpleVo> lanTopOperCharacter = upLoader.getLookUpListByType("CBB_OPER_CHARACTER");
		Collection<SysLookupSimpleVo> lanTopLogicOper = upLoader.getLookUpListByType("CBB_LOGIC_OPER");
		ModelAndView mav = new ModelAndView();
		String dialogId = request.getParameter("dialogId");
		String sysId = request.getParameter("sysId");
		String id = request.getParameter("id");// 字段对应设置主表ID
		mav.addObject("id", id);
		String nodeCode = request.getParameter("nodeCode");
		mav.addObject("dialogId", dialogId);
		mav.addObject("nodeCode", nodeCode);
		mav.addObject("sysId", sysId);
		// 根据字段对应设置ID获取源表ID
		String sourceTabId = this.lantopFieldMapSetService.getSourceTabIdByRetaleIdSetId(id);
		mav.addObject("checkNodeIds", sourceTabId);
		// 根据字段对应设置主表ID获取条件设置信息
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		list = this.lantopFieldMapSetService.getConditionByRetaleIdSetId(id);
		//StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			//Map<String, Object> map = list.get(i);
			// 获取左括号下拉框数据
			String zkh = "";
			zkh = "[{id:'(',text:'('}]";
			mav.addObject("zkh", zkh);

			// 获取右括号下拉框数据
			String ykh = "";
			ykh = "[{id:')',text:')'}]";
			mav.addObject("ykh", ykh);

			// 获取运算符下拉框数据
			StringBuffer sbysf = new StringBuffer();
			sbysf.append("[");
			Iterator<SysLookupSimpleVo> itysf = lanTopOperCharacter.iterator();
			while (itysf.hasNext()) {
				SysLookupSimpleVo sysLookupSimpleVo = (SysLookupSimpleVo) itysf.next();
				String idysf = sysLookupSimpleVo.getLookupCode();
				String textysf = sysLookupSimpleVo.getLookupName();
				sbysf.append("{id:'" + idysf + "',");
				sbysf.append("text:'" + textysf + "'");
				sbysf.append("},");
			}
			String ysf = sbysf.subSequence(0, sbysf.length() - 1).toString();
			ysf = ysf + "]";
			mav.addObject("ysf", ysf);

			// 获取并且/或者下拉框数据
			StringBuffer sbhzbq = new StringBuffer();
			sbhzbq.append("[");
			Iterator<SysLookupSimpleVo> ithzbq = lanTopLogicOper.iterator();
			while (ithzbq.hasNext()) {
				SysLookupSimpleVo sysLookupSimpleVo = (SysLookupSimpleVo) ithzbq.next();
				String idhzbq = sysLookupSimpleVo.getLookupCode();
				String texthzbq = sysLookupSimpleVo.getLookupName();
				sbhzbq.append("{id:'" + idhzbq + "',");
				sbhzbq.append("text:'" + texthzbq + "'");
				sbhzbq.append("},");
			}
			String hzbq = sbhzbq.subSequence(0, sbhzbq.length() - 1).toString();
			hzbq = hzbq + "]";
			mav.addObject("hzbq", hzbq);

			// 获取字段下拉框数据
			StringBuffer sbCol = new StringBuffer();
			sbCol.append("[");
			List<Map<String, Object>> listCol = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabIdByIntfs(sourceTabId);
			for (int j = 0; j < listCol.size(); j++) {
				Map<String, Object> mapCol = listCol.get(j);
				String colName = String.valueOf(mapCol.get("COL_NAME"));// 列英文名
				String colLabel = String.valueOf(mapCol.get("COL_LABEL"));// 列名
				sbCol.append("{id:'" + colName + "',");
				sbCol.append("text:'" + colLabel + "'},");
			}
			String colAndField = sbCol.subSequence(0, sbCol.length() - 1).toString();
			colAndField = colAndField + "]";
			mav.addObject("colAndField", colAndField);
		}
		mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopConditionSetEditFormItem");
		return mav;
	}

	/**
	 * 初始化编辑页面
	 * 
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/initConditionEditItem")
	public ModelAndView initConditionEditItem(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Collection<SysLookupSimpleVo> lanTopOperCharacter = upLoader.getLookUpListByType("CBB_OPER_CHARACTER");
		Collection<SysLookupSimpleVo> lanTopLogicOper = upLoader.getLookUpListByType("CBB_LOGIC_OPER");
		ModelAndView mav = new ModelAndView("");
		try {
			String id = request.getParameter("id");// 字段对应设置主表ID
			// 根据字段对应设置ID获取源表ID
			String sourceTabId = this.lantopFieldMapSetService.getSourceTabIdByRetaleIdSetId(id);
			// 根据字段对应设置主表ID获取条件设置信息
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			list = this.lantopFieldMapSetService.getConditionByRetaleIdSetId(id);
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = list.get(i);
				// 获取左括号下拉框数据
				String zkh = "";
				if ("(".equals(map.get("LEFT_BRACKET"))) {
					zkh = "[{id:'(',text:'(',selected:true}]";
				} else {
					zkh = "[{id:'(',text:'('}]";
				}
				// 获取右括号下拉框数据
				String ykh = "";
				if (")".equals(map.get("RIGHT_BRACKET"))) {
					ykh = "[{id:')',text:')',selected:true}]";
				} else {
					ykh = "[{id:')',text:')'}]";
				}
				// 获取运算符下拉框数据
				StringBuffer sbysf = new StringBuffer();
				sbysf.append("[");
				Iterator<SysLookupSimpleVo> itysf = lanTopOperCharacter.iterator();
				while (itysf.hasNext()) {
					SysLookupSimpleVo sysLookupSimpleVo = (SysLookupSimpleVo) itysf.next();
					String idysf = sysLookupSimpleVo.getLookupCode();
					String textysf = sysLookupSimpleVo.getLookupName();
					if (idysf.equals(map.get("OPER_CHARACTER"))) {
						sbysf.append("{id:'" + idysf + "',");
						sbysf.append("text:'" + textysf + "',");
						sbysf.append("selected:true");
						sbysf.append("},");
					} else {
						sbysf.append("{id:'" + idysf + "',");
						sbysf.append("text:'" + textysf + "'");
						sbysf.append("},");
					}
				}
				String ysf = sbysf.subSequence(0, sbysf.length() - 1).toString();
				ysf = ysf + "]";
				// 获取并且/或者下拉框数据
				StringBuffer sbhzbq = new StringBuffer();
				sbhzbq.append("[");
				Iterator<SysLookupSimpleVo> ithzbq = lanTopLogicOper.iterator();
				while (ithzbq.hasNext()) {
					SysLookupSimpleVo sysLookupSimpleVo = (SysLookupSimpleVo) ithzbq.next();
					String idhzbq = sysLookupSimpleVo.getLookupCode();
					String texthzbq = sysLookupSimpleVo.getLookupName();
					if (idhzbq.equals(map.get("LOGIC_OPER"))) {
						sbhzbq.append("{id:'" + idhzbq + "',");
						sbhzbq.append("text:'" + texthzbq + "',");
						sbhzbq.append("selected:true");
						sbhzbq.append("},");
					} else {
						sbhzbq.append("{id:'" + idhzbq + "',");
						sbhzbq.append("text:'" + texthzbq + "'");
						sbhzbq.append("},");
					}
				}
				String hzbq = sbhzbq.subSequence(0, sbhzbq.length() - 1).toString();
				hzbq = hzbq + "]";
				// 获取字段下拉框数据
				StringBuffer sbCol = new StringBuffer();
				sbCol.append("[");
				List<Map<String, Object>> listCol = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabIdByIntfs(sourceTabId);
				for (int j = 0; j < listCol.size(); j++) {
					Map<String, Object> mapCol = listCol.get(j);
					String colName = String.valueOf(mapCol.get("COL_NAME"));// 列英文名
					String colLabel = String.valueOf(mapCol.get("COL_LABEL"));// 列名
					if (colName.equals(map.get("FIELD_NAME_EN"))) {
						sbCol.append("{id:'" + colName + "',");
						sbCol.append("text:'" + colLabel + "',selected:true},");
					} else {
						sbCol.append("{id:'" + colName + "',");
						sbCol.append("text:'" + colLabel + "'},");
					}
				}
				String colAndField = sbCol.subSequence(0, sbCol.length() - 1).toString();
				colAndField = colAndField + "]";
				// 拼写编辑页面初始化脚本
				sb.append("<tr id='" + i + "' style='border: 0px;'>");
				sb.append("<td style='border: 0px;'>");
				sb.append("<input class='easyui-combobox' ");
				sb.append("data-options=" + '\"' + "valueField:'id',textField:'text',data:" + zkh + '\"' + "></td>");
				sb.append("<td style='border: 0px;'>");
				sb.append("<input class='easyui-combobox' ");
				sb.append("data-options=" + '\"' + "valueField:'id',textField:'text',data:" + colAndField + '\"' + "></td>");
				sb.append("<td style='border: 0px;'>");
				sb.append("<input class='easyui-combobox' ");
				sb.append("data-options=" + '\"' + "valueField:'id',textField:'text',data:" + ysf + '\"' + "></td>");
				sb.append("<td style='border: 0px;'><input type='text' class='easyui-validatebox' value='" + map.get("FILED_VALUE") + "'/></td>");
				sb.append("<td style='border: 0px;'>");
				sb.append("<input class='easyui-combobox' ");
				sb.append("data-options=" + '\"' + "valueField:'id',textField:'text',data:" + ykh + '\"' + "></td>");
				sb.append("<td style='border: 0px;'>");
				sb.append("<input class='easyui-combobox' ");
				sb.append("data-options=" + '\"' + "valueField:'id',textField:'text',data:" + hzbq + '\"' + ">");
				sb.append("</td>");
				sb.append("<td style='border: 0px;'><a class='easyui-linkbutton' plain='true' iconCls='icon-im-remove' onclick='deltr(this);'href='javascript:void(0);' id='deleteForm'>删除</a></td>");
				sb.append("</tr>");
			}
			mav.addObject("data", sb.toString());
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure);
			e.printStackTrace();
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 加载目标节点数据
	 * 
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/getTgtNodeData")
	public ModelAndView getTgtNodeData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String id = request.getParameter("id");
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		String orgId = SessionHelper.getCurrentOrgId(request);
		try {
			// 根据节点ID查找parentId
			String pid = lantopFieldMapSetService.findParentIdById(id);
			nodes = lantopFieldMapSetService.findTreeNodesByParentId(pid, null, orgId);
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			mav.addObject("flag", OpResult.failure);
			mav.addObject("msg", "后台处理异常，" + e.getMessage());
		}
		mav.addObject("data", nodes);
		return mav;
	}

	/**
	 * 删除字段对应设置
	 * 
	 * @author 朱锋
	 * @param request
	 * @return ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteMapSet")
	public Map<String,Object> deleteMapSet(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<>();
		try {
			String ids = request.getParameter("ids");
//			String sysId = request.getParameter("sysId");
			if (ids != null && !"".equals(ids)) {
				this.lantopFieldMapSetService.deleteMapSet(ids);
				String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
				SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
				String orgCode = so.getOrgCode();
				// 调用存储过程更新或建立大试图
				ArrayList<Object> params = new ArrayList<Object>();
				params.add(0, "LANTOP");
				String tempOrgCode = orgCode;
				if (orgCode.length() > 16) {
					tempOrgCode = orgCode.substring(orgCode.length() - 16);
				}
				params.add(1, tempOrgCode);
//				String status = 
						lantopFieldMapSetManagerDao.callProcedure("LANTOP_DATA_P.LANTOP_DATA_V", params);
				SysLogUtil.log("档案业务模块", "更新档案大视图", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
				map.put("flag", OpResult.success);
			}
		} catch (Exception e) {
			map.put("flag", OpResult.failure);
		}
		return map;
	}

	/**
	 * 删除条件设置信息
	 * 
	 * @author 朱锋
	 * @param request
	 * @return ModelAndView
	 * @throws
	 */
	@RequestMapping("/deleteConditionSet")
	public ModelAndView deleteConditionSet(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		try {
			String ids = request.getParameter("ids");
			if (ids != null && !"".equals(ids)) {
				this.lantopFieldMapSetService.deleteConditionSet(ids);
				String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
				SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
				String orgCode = so.getOrgCode();
				// 调用存储过程更新或建立大试图
				ArrayList<Object> params = new ArrayList<Object>();
				params.add(0, SessionHelper.getCurrentOrgId(request));
				String tempOrgCode = orgCode;
				if (orgCode.length() > 16) {
					tempOrgCode = orgCode.substring(orgCode.length() - 16);
				}
				params.add(1, tempOrgCode);
//				String status = 
						lantopFieldMapSetManagerDao.callProcedure("LANTOP_DATA_P.LANTOP_DATA_V", params);
				SysLogUtil.log("档案业务模块", "更新档案大视图", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
				mav.addObject("flag", OpResult.success);
			} else {
				mav.addObject("flag", OpResult.failure);
			}
		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject("flag", OpResult.failure);
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 新增字段对应设置
	 * 
	 * @author 朱锋
	 * @param request
	 * @return ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveSetData")
	public ModelAndView saveSetData(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		try {
			String rowDatas = request.getParameter("rowDatas");// 对应数据
			String sysId = request.getParameter("sysId");// 系统标识
			String sourceTableId = request.getParameter("sourceTableId");// 源库表ID
			String tgtTableId = request.getParameter("tgtTableId");// 目标库表ID
			String tgtNodeId = request.getParameter("tgtNodeId");// 目标节点
			String relateSetId = this.lantopFieldMapSetService.getRelateSetIdByIds(sourceTableId, tgtTableId, tgtNodeId, sysId, "source");
			if ("".equals(relateSetId)) {
				// 如果为空，那么新增字段对应设置主表信息
				relateSetId = ComUtil.getId();
				this.lantopFieldMapSetService.insertRelateSet(relateSetId, sourceTableId, tgtTableId, tgtNodeId, sysId, "-1");
			}
			// 添加现有的全部字段对应信息
			this.lantopFieldMapSetService.insertRelateSetItem(rowDatas, relateSetId, sysId);
			boolean flag = false;//初始化为否
			List<Map<String, Object>> tableInfoList = commTableManagerIntfsService.getCbbTableAndColumnsByTabIdByIntfs(tgtTableId);
			if(tableInfoList.size() > 0){
				Map<String, Object> tmap = tableInfoList.get(0);
				String tableName = String.valueOf(tmap.get("TABLE_NAME"));
				if(null != tableName && "LANTOP_PUB_FIELD".equals(tableName)){
					flag = true;
				}
			}
			String orgId = SessionHelper.getCurrentOrgId(request);
			String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
			SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
			String orgCode = so.getOrgCode();
			//如果目标表是公共字段,那么更新大视图及更新源表索引
			if(flag){
				// 调用存储过程更新或建立大视图
				ArrayList<Object> params = new ArrayList<Object>();
				params.add(0, orgId);
				String tempOrgCode = orgCode;
				if (orgCode.length() > 16) {
					tempOrgCode = orgCode.substring(orgCode.length() - 16);
				}
				params.add(1, tempOrgCode);
				lantopFieldMapSetManagerDao.callProcedure("LANTOP_DATA_P.LANTOP_DATA_V", params);
				SysLogUtil.log("档案业务模块", "更新档案大视图", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
			}
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject("flag", OpResult.failure);
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 条件设置跳转
	 * 
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/getFlagConditionSet")
	public ModelAndView getFlagConditionSet(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		String id = request.getParameter("id");
		String nodeName = request.getParameter("nodeName");
		boolean flag = true;
		try {
			flag = this.lantopFieldMapSetService.getFlagConditionSet(id);
			mav.addObject("ext", flag);
			mav.addObject("id", id);
			mav.addObject("nodeName", nodeName);
			mav.addObject("flag", OpResult.success);
		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject("flag", OpResult.failure);
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 前台展开时异步加载树(条件设置添加页面)
	 * 
	 * @author 朱锋
	 * @param
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */

	@RequestMapping("/findLantopConditionzkh")
	public String findLantopConditionzkh(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String obj = "[{id:'Y',text:'是'},{id:'N',text:'否'}]";
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.write(obj);
		out.close();
		return null;
	}

	/**
	 * 条件详细页跳转
	 * 
	 * @author 朱锋
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/toConditionSetItemPage")
	public ModelAndView toConditionSetItemPage(HttpServletRequest request) throws Exception {
		Collection<SysLookupSimpleVo> lanTopOperCharacter = upLoader.getLookUpListByType("CBB_OPER_CHARACTER");
		Collection<SysLookupSimpleVo> lanTopLogicOper = upLoader.getLookUpListByType("CBB_LOGIC_OPER");
		ModelAndView mav = new ModelAndView();
		String sysId = request.getParameter("sysId");
		mav.addObject("sysId", sysId);
		String nodeCode = request.getParameter("nodeCode");
		mav.addObject("nodeCode", nodeCode);
		String dialogId = request.getParameter("dialogId");
		mav.addObject("dialogId", dialogId);
		String orgId = SessionHelper.getCurrentOrgId(request);
		String deptId = SessionHelper.getCurrentDeptId(request);
		// 获取左括号下拉框数据
		String zkh = "[{id:'(',text:'('}]";
		mav.addObject("zkh", zkh);
		// 获取右括号下拉框数据
		String ykh = "[{id:')',text:')'}]";
		mav.addObject("ykh", ykh);
		// 获取运算符下拉框数据
		StringBuffer sbysf = new StringBuffer();
		sbysf.append("[");
		Iterator<SysLookupSimpleVo> itysf = lanTopOperCharacter.iterator();
		while (itysf.hasNext()) {
			SysLookupSimpleVo sysLookupSimpleVo = (SysLookupSimpleVo) itysf.next();
			String id = sysLookupSimpleVo.getLookupCode();
			String text = sysLookupSimpleVo.getLookupName();
			sbysf.append("{id:'" + id + "',");
			sbysf.append("text:'" + text + "'");
			sbysf.append("},");
		}
		String ysf = sbysf.subSequence(0, sbysf.length() - 1).toString();
		ysf = ysf + "]";
		mav.addObject("ysf", ysf);
		// 获取并且/或者下拉框数据
		StringBuffer sbhzbq = new StringBuffer();
		sbhzbq.append("[");
		Iterator<SysLookupSimpleVo> ithzbq = lanTopLogicOper.iterator();
		while (ithzbq.hasNext()) {
			SysLookupSimpleVo sysLookupSimpleVo = (SysLookupSimpleVo) ithzbq.next();
			String id = sysLookupSimpleVo.getLookupCode();
			String text = sysLookupSimpleVo.getLookupName();
			sbhzbq.append("{id:'" + id + "',");
			sbhzbq.append("text:'" + text + "'");
			sbhzbq.append("},");
		}
		String hzbq = sbhzbq.subSequence(0, sbhzbq.length() - 1).toString();
		hzbq = hzbq + "]";
		mav.addObject("hzbq", hzbq);
		// 获取字段下拉框数据
		String checkNodeIds = request.getParameter("checkNodeIds");
		mav.addObject("checkNodeIds", checkNodeIds);
		String[] tableIds = checkNodeIds.split(";");
		if (tableIds.length == 1) {
			StringBuffer sbCol = new StringBuffer();
			sbCol.append("[");
			String tableId = tableIds[0];
			List<Map<String, Object>> listCol = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabIdByIntfs(tableId);
			for (int i = 0; i < listCol.size(); i++) {
				Map<String, Object> mapCol = listCol.get(i);
				String colName = String.valueOf(mapCol.get("COL_NAME"));// 列英文名
				String colLabel = String.valueOf(mapCol.get("COL_LABEL"));// 列名
				sbCol.append("{id:'" + colName + "',");
				sbCol.append("text:'" + colLabel + "'},");
			}
			String colAndField = sbCol.subSequence(0, sbCol.length() - 1).toString();
			colAndField = colAndField + "]";
			mav.addObject("colAndField", colAndField);
		} else if (tableIds.length > 1) {
			StringBuffer sbCol = new StringBuffer();
			sbCol.append("[");
			String tableName = "LANTOP_PUB_FIELD";
			List<Map<String, Object>> listFiled = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabNameByIntfs(orgId, deptId, sysId, tableName);
			for (int i = 0; i < listFiled.size(); i++) {
				Map<String, Object> mapField = listFiled.get(i);
				String fieldName = String.valueOf(mapField.get("COL_NAME"));// 列英文名
				String fieldLabel = String.valueOf(mapField.get("COL_LABEL"));// 列名
				sbCol.append("{id:'" + fieldName + "',");
				sbCol.append("text:'" + fieldLabel + "'},");
			}
			String colAndField = sbCol.subSequence(0, sbCol.length() - 1).toString();
			colAndField = colAndField + "]";
			mav.addObject("colAndField", colAndField);
		}
		mav.setViewName("avicit/im/lantop/basic/fieldmapset/LantopConditionSetAddFormItem");
		return mav;
	}

	/**
	 * 保存条件设置详细信息
	 * 
	 * @author 朱锋
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/saveConditionItem")
	public ModelAndView saveConditionItem(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("");
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		String json = request.getParameter("json");
		String sysCode = request.getParameter("sysId");
		// sysId
		String sysId = "LANTOP";
		String orgId = SessionHelper.getCurrentOrgId(request);
		String deptId = SessionHelper.getCurrentDeptId(request);
		String tableName = "LANTOP_PUB_FIELD";
		List<Map<String, Object>> listFiled = this.commTableManagerIntfsService.getCbbTableAndColumnsByTabNameByIntfs(orgId, deptId, sysId, tableName);
		if (listFiled.size() > 0) {
			String tableId = String.valueOf(listFiled.get(0).get("TABLE_ID"));// 公共字段表ID
			try {
				String checkNodeIds = request.getParameter("checkNodeIds");
				String[] sourceIds = checkNodeIds.split(";");
				for (int i = 0; i < sourceIds.length; i++) {
					String sourceTableId = sourceIds[i];
					// 获取字段对应设置信息ID
					String lantopFieldRelateSetId = this.lantopFieldMapSetService.getRelateSetIdByIds(sourceTableId, tableId, "", sysId, "source");
					// 删除条件设置信息
					this.lantopFieldMapSetService.deleteConditionSetByRelateSetId(lantopFieldRelateSetId);
					// 新增条件设置信息,并且返回过滤条件SQL和中文过滤条件
					Map<String, String> map = this.lantopFieldMapSetService.insertConditionSet(json, sysId, lantopFieldRelateSetId);
					list.add(map);
				}
				// 更新字段对应设置表SQL部分数据
				this.lantopFieldMapSetService.updateRelateSetSqlByList(checkNodeIds, tableId, list, sysId);
				String orgIdentity = SessionHelper.getCurrentOrgIdentity(request);
				SysOrg so = sysOrgAPI.getSysOrgBySysOrgId(orgIdentity);
				String orgCode = so.getOrgCode();
				// 调用存储过程更新或建立大试图
				ArrayList<Object> params = new ArrayList<Object>();
				params.add(0, SessionHelper.getCurrentOrgId(request));
				String tempOrgCode = orgCode;
				if (orgCode.length() > 16) {
					tempOrgCode = orgCode.substring(orgCode.length() - 16);
				}
				params.add(1, tempOrgCode);
//				String status = 
						lantopFieldMapSetManagerDao.callProcedure("LANTOP_DATA_P.LANTOP_DATA_V", params);
				SysLogUtil.log("档案业务模块", "更新档案大视图", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
				mav.addObject("flag", OpResult.success);
			} catch (Exception e) {
				mav.addObject("flag", OpResult.failure);
				e.printStackTrace();
			}
		}
		mav.setView(null);
		return mav;
	}

	/**
	 * 字段对应设置选择库表加载树
	 * 
	 * @author 朱锋
	 * @param
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/fieldMapSetTree")
	@ResponseBody
	public Map<String,Object> fieldMapSetTree(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String type = request.getParameter("type");// 节点属性标识（Y 真实表 N 虚拟表 ）
		String flag = request.getParameter("flag");// 添加，编辑标识（添加'add' 编辑'edit'
		String sOrt = request.getParameter("sOrt");// 源库表，目标库表 标识 （源库表：s，目标库表：t）
		String orgType = request.getParameter("orgType");
		String orgId = "";
		if(orgType!="null" && orgType !=null){
			if(orgType.equals("1")){
				orgId =request.getParameter("orgId");
			}else{
				orgId = ThreadContextHelper.getOrgId();
			}
		}else{
			orgId = ThreadContextHelper.getOrgId();
		}

//		String orgId = "ORG_ROOT";
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		try {
			nodes = this.lantopFieldMapSetService.selectTableFindTreeNodesByParentId("ROOT", type, flag, sOrt, orgId);
			List<Map<String, Object>> publicFieldList =  this.lantopFieldMapSetService.getPublicFieldInfo();
			Map<String, Object> modelMap = new HashMap<String, Object>();
			Map<String, Object> FolderMap = new HashMap<String, Object>();
			for (int i = 0; i < publicFieldList.size(); i++) {
				Map<String, Object> map = publicFieldList.get(i);
				String archiveType = (String) map.get("ARCHIVE_TYPE");
				if ("-1".equals(archiveType)) {
					modelMap = map;
				} else {
					FolderMap = map;
				}
			}
			TreeNode model = new TreeNode();
			String ridModel = (String) modelMap.get("ID");
			String rnameModel = (String) modelMap.get("ARCHIVE_CLASS_NODE_NAME");
			String parentIdModel = (String) modelMap.get("PARENT_ID");
			model.setId(ridModel);
			model.setText(rnameModel);
			model.setAttributes(modelMap);
			model.set_parentId(parentIdModel);
			model.setIconCls("icon-im-newntable");
			TreeNode folder = new TreeNode();
			String rid = (String) FolderMap.get("ID");
			String rname = (String) FolderMap.get("ARCHIVE_CLASS_NODE_NAME");
			String parentId = (String) FolderMap.get("PARENT_ID");
			folder.setId(rid);
			folder.setText(rname);
			folder.setAttributes(FolderMap);
			folder.set_parentId(parentId);
			folder.setState("open");
			folder.setIconCls("icon-im-newnmodulelib");
			folder.getChildren().add(model);
			nodes.get(0).getChildren().add(folder);
			maps.put("flag", OpResult.success);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			maps.put("flag", OpResult.failure);
			maps.put("msg", "后台处理异常，" + e.getMessage());
		}
		if (ThreadContextHelper.getOrgId()!="ORG_ROOT"||!ThreadContextHelper.getOrgId().equals("ORG_ROOT")){
			List<TreeNode> treeNodeList = this.archiveClassManagerIntfsService.getArchiveClassTreeNodeToTableInfoByIntfs("ORG_ROOT","");
			treeNodeList = treeNodeList.get(0).getChildren();
			int index = 0;
			for (TreeNode treeNode : treeNodeList){
				String text = treeNode.getText();
				if (text.equals("外部业务系统归档接收管理")){
					break;
				}
				index++;
			}
			nodes.get(0).getChildren().add(treeNodeList.get(index));
		}
		maps.put("data", nodes);
		return maps;
	}

	/**
	 * 验证该表是否存在字段对应设置信息
	 * 
	 * @author 朱锋
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/checkMapSetItem")
	public ModelAndView checkMapSetItem(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView();
		String tableId = request.getParameter("tableId");
		try {
			int num = lantopFieldMapSetService.checkMapSetItem(tableId);
			// 0-正常 1-没有字段对应设置主表信息 2-没有字段对应设置子表信息
			if (num == 1) {
				mv.addObject("flag", OpResult.failure);
				mv.addObject("msg", "请先配置该物理表的字段对应设置信息，再进行选择！");
			} else if (num == 2) {
				mv.addObject("flag", OpResult.failure);
				mv.addObject("msg", "请先配置该物理表的字段对应设置详细信息，再进行选择！");
			} else {
				mv.addObject("flag", OpResult.success);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			mv.addObject("flag", OpResult.failure);
			mv.addObject("msg", "后台处理异常，" + e.getMessage());
		}
		return mv;
	}
}
